// compose组合函数;
// 组合函数的调试
// lodash的fp
const _ = require("lodash");

function compose(...args) {
    return function (a) {
        return args.reverse().reduce((pre, current) => current(pre), a);
    };
}

var str = "hello lsq";

const split = (a) => a.split(" ");

const reverse = (a) => a.reverse();

const log = (res) => {
    console.log(res);
    return res;
};

const trace = _.curry((tag, value) => {
    console.log(tag, value);
    return value;
});

const composeFn = compose(reverse, log, trace("split方法后的结果"), split);

console.log(composeFn(str));

const fp = require("lodash/fp");

const fn = fp.flowRight(fp.join(""), fp.map(fp.upperCase), fp.split(""));
console.log(fn("hello world"));

// _.map 与 fp.map 的区别
console.log(_.map(["8", "12", "10"], parseInt));
console.log(fp.map(parseInt, ["8", "12", "10"]));
